/*
 * @Author: your name
 * @Date: 2021-01-22 10:57:28
 * @LastEditTime: 2021-02-25 13:45:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \water-garbagee:\vue3-ts\src\utils\verify\verify.ts
 */

/**
 * @description: 姓名校验 由2-10位汉字组成
 * @param {String} str
 * @return {Boolean}
 */
export const validateCompellation = (str: string): boolean => {
  const reg = /^[\u4e00-\u9fa5]{2,10}$/;
  return reg.test(str);
};

/**
 * @description: 手机号码校验 11位数字组成
 * @param {String} str
 * @return {Boolean}
 */
export const validateMobile = (str: string): boolean => {
  const reg = /^1[3456789]{1}\d{9}$/;
  return reg.test(str);
};

/**
 * @description: 两位小数校验
 * @param @param {String} str
 * @return {Boolean}
 */
export const validateDecimals = (str: string): boolean => {
  const reg = /^\d{1,10}\.?(?=.) \d{0,2}$/;
  return reg.test(str);
};

/**
 * @description: 百分比校验(整数)
 * @param {String} str
 * @return {Boolean}
 */
export const validatePercent = (str: string): boolean => {
  const reg = /^(\d|[1-9]\d|100)$/;
  return reg.test(str);
};

/**
 * @description: 座机号码校验
 * @param {String} str
 * @return {Boolean}
 */
export const validateSpecialPlane = (str: string): boolean => {
  const reg = /^(0\d{2,3}-?)(\d{7,8})(-?(\d{3,}))?$/;
  return reg.test(str);
};

/**
 * @description: 身份证校验 支持1代(15位)、2代(18位)
 * @param {String} str
 * @return {Boolean}
 */
export const validateIdentityCard = (str: string): boolean => {
  const reg = /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;
  return reg.test(str);
};

/**
 * @description: 数字和字母组成的校验 且需同时含有数字、英文字母
 * @param {String} str
 * @return {Boolean}
 */
export const validateDigitalAlphabet = (str: string): boolean => {
  const reg = /^(?=.*[a-zA-Z])(?=.*\d).+$/;
  return reg.test(str);
};

/**
 * @description: 用户名校验，4到16位（字母，数字，下划线，减号）
 * @param {String} str
 * @return {Boolean}
 */
export const validateUsername = (str: string): boolean => {
  const reg = /^[a-zA-Z0-9_-]{4,16}$/;
  return reg.test(str);
};

/**
 * @description: 银行卡号(10-30位 覆盖对公、私账户)
 * @param {String} str
 * @return {Boolean}
 */
export const validateBankCard = (str: string): boolean => {
  const reg = /^[1-9]\d{9,29}$/;
  return reg.test(str);
};
